// Calculate electric field from potential

#include "mine.h"

void Electric (Array<double,1> phi, Array<double,1>& E)
{
    double dx = L / double (J);
    
    for (int j = 1; j < J-1; j++)
	E(j) = (phi(j-1) - phi(j+1)) / 2.0 / dx;
    
    E(0) = (phi(J-1) - phi(1)) / 2.0 / dx;
    E(J-1) = (phi(J-2) - phi(0)) / 2.0 / dx;
}
